package com.tuyan.aixiang.component;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tuyan.aixiang.R;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;

public class DeviceControlItem extends LinearLayout {

    @BindView(R.id.iv_icon)
    ImageView ivIcon;

    @BindView(R.id.tv_title)
    TextView tvTitle;

    public DeviceControlItem(Context context) {
        this(context, null);
    }

    public DeviceControlItem(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DeviceControlItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View contentView = LayoutInflater.from(context).inflate(R.layout.item_device_control, this);
        ButterKnife.bind(contentView, this);

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.DeviceControlItem);
        String tx = ta.getString(R.styleable.DeviceControlItem_dci_tt);
        int icon = ta.getResourceId(R.styleable.DeviceControlItem_dci_icon, 0);
        tvTitle.setText(tx);
        setIcon(icon);
        ta.recycle();
    }

    private void setIcon(int res) {
        ivIcon.setImageResource(res);
    }
}
